#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define DEBUG
using ll=long long;
inline int read()
{
    int c=getchar(), f=1, x=0;
    if(c=='-') f*=-1, c=getchar();
    while(c<'0'&&'9'<c) c=getchar();
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    return f*x;
}

inline void write(int x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}
const int N=2010, INF=0x3f3f3f3f;

struct node {
    int id, v; //编号 单点权值
    ll treeW; //子树权值
    node *fa;
    vector<node*> sons;
} nd[N];

struct LinkNode {
    node* val;
    LinkNode* next[2]; //小 大
    LinkNode() {next[0]=nullptr, next[1]=nullptr;}
};
int n, m, q, st; //
node* root;
LinkNode *lknd=new LinkNode;
void init()
{
    n=read(), m=read();
    for(int i=1; i<=n; i++)
        nd[i].v=read(), nd[i].id=i;
    nd[1].fa=nullptr;
    for(int i=2; i<=n; i++)
    {
        int f=read();
        nd[i].fa=&nd[f];
        nd[f].sons.push_back(&nd[i]);
    }
    root=&nd[1];
}

void cal(node* u)
{
    //计算子树权值
    u->treeW=u->v;
    for(node* son: u->sons)
    {
        cal(son);
        u->treeW+=son->treeW;
    }
}

void solve()
{
    init();
    cal(root);

    while(m--)
    {
        q=read();
        node *cur=root; //完整的树
        cal(root);
        LinkNode *linku=lknd;
        st=0;
        while(true)
        {
            // printf("while\n");
            if(linku->next[st]==nullptr) //未搜索
            {
                //找到这棵树的最小值
                node *ans=cur, *p=cur;
                ll A=abs(cur->treeW-2*ans->treeW);
                while(p!=nullptr)
                {
                    node *next=nullptr;
                    for(auto son:p->sons)
                    {
                        if(son->treeW)
                        {
                            ll B=abs(cur->treeW-2*son->treeW);
                            if(A>B || (A==B&&son->id<ans->id))
                            {
                                ans=son;
                                A=B;
                            }
                            if(cur->treeW>=2*son->treeW) continue;
                            next=son;
                        }
                    }
                    p=next;
                }
                if(ans==cur) break; //空树
                linku->next[st]=new LinkNode;
                linku->next[st]->val=ans;
            }
            //转移
            linku=linku->next[st];

            write(linku->val->id); putchar(' ');

            //判断是否在树上
            node *p=&nd[q];
            bool flag=false;
            while(p!=cur->fa)
            {
                if(p==linku->val) {flag=1; cur=linku->val; st=1; break;} //在树上
                p=p->fa;
            }

            if(!flag)
            {
                //删除
                st=0;
                node *p2=linku->val->fa;
                while(p2!=cur->fa)
                {
                    p2->treeW-=linku->val->treeW;
                    p2=p2->fa;
                }
                linku->val->treeW=0;
            }
        }
        puts("");
    }
}

signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif

    int T=1; //cin >> T; 
    while(T--) 
    {
        solve();
    }
    return 0;
}